###RStudio version 2022.07.2 +576
### necessary packages:
### openxlsx, ggplot2, tidyverse, PolicyPortfolios, patchwork

library(openxlsx)
library(ggplot2)
library(tidyverse)
library(PolicyPortfolios)

### set working directory to where the file is saved

setwd("C:/Users/Christian/Desktop/Paper/Replications")

### Figure 2: Singapore's Policy Portfolio Development
### Yearly development of Singapore's environmental policy portfolio between 1976 to 2020.

singagrowth <- read.xlsx("ReplicationData.xlsx", sheet = 1)

p <- ggplot(singagrowth, aes(Year, Size, color=Country)) + geom_line(colour="black", size=2) + theme_bw() + xlim(1976, 2020) + ylim(0, 0.1) + geom_segment(aes(x = 1976, y = 0, xend = 1976, yend = 0.029), colour = "black", show.legend = F) +
  geom_segment(aes(x = 1978, y = 0, xend = 1978, yend = 0.04), colour = "black", show.legend = F) + geom_segment(aes(x = 1999, y = 0, xend = 1999, yend = 0.054), colour="black", show.legend = F) +
  geom_segment(aes(x = 2012, y = 0, xend = 2012, yend = 0.055), colour="black", show.legend = F) + geom_segment(aes(x = 2017, y = 0, xend = 2017, yend = 0.06), colour="black", show.legend = F) +
  geom_segment(aes(x = 2018, y = 0, xend = 2018, yend = 0.063), colour="black", show.legend = F) + theme(text = element_text(size = 20))

print(p)


### Figure 3: Singapore's Policy Portfolio Development in Comparison
### From the data we compare the Yearly Max, Yearly Min and Yearly Mean with the portfolio development of Singapore.
### The Yearly Max denotes the largest portfolio size in the sample for every year between 1976 to 2020.
### The Yearly Min denotes the smallest portfolio size in the sample for every year between 1976 to 2020.
### The Yearly Mean denotes the average portfolio size of the country sample for every year between 1976 to 2020.
### The data is calculated from the full data sample.

sgm <- read.xlsx("ReplicationData.xlsx", sheet = 2)

sgmdata <- ggplot(sgm, aes(x=Year, y=Size, color=Country)) + geom_line(aes(linetype = Country), size = 2) + scale_linetype_manual(values = c("solid", "dashed", "solid", "dashed")) + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 20))

print(sgmdata)

### Figure 4: Policy Portfolio Development in High GDP pc Countries
### Sample of high GDP pc Countries according to data from the World Bank (2022)
### Based on the yearly growth rate, we calculate the Mean Growth Rate for each country
### High GDPpc countries: Ireland, Denmark, Switzerland, USA, Norway

growth_ratesmall <- read.xlsx("ReplicationData.xlsx", sheet = 3) %>%
  group_by(Country) %>%
  mutate(Diff_Year = Year - lag(Year),
         Diff_Size = Size - lag(Size),
         Rate = (Diff_Size/Diff_Year)/lag(Size))

growth_ratesmall1 <- growth_ratesmall %>% drop_na(Diff_Size)
mean_growth_ratesmall <- aggregate(growth_ratesmall1$Diff_Size, list(growth_ratesmall1$Country), FUN=mean)

mean_growth_ratesmall <- mean_growth_ratesmall %>%
  arrange(x) %>%
  mutate(rank = row_number())

small_lolli <- ggplot(mean_growth_ratesmall, aes(x = rank, y = x)) + 
  geom_segment(aes(x = rank, xend = rank, y = 0, yend = x), size = 2) + geom_point(size = 3) + scale_color_grey() + coord_flip() + scale_x_continuous(breaks = mean_growth_ratesmall$rank, labels = mean_growth_ratesmall$Group.1) + labs(x = "Countries", y = "Mean Growth Rate") + theme_bw() + theme(text = element_text(size = 20))
print(small_lolli)

### Figure 5: Policy Portfolio Development in Countries with Highly Effective Administrations
### Government effectiveness data taken from the worldwide governance indicators by Kaufmann et al. (2010)
### Based on the yearly growth rate, we calculate the Mean Growth Rate for each country
### Countries with high government effectiveness: Sweden, Netherlands, Denmark, Switzerland, Finland, and Norway

growth_rateburgov <- read.xlsx("ReplicationData.xlsx", sheet = 4) %>%
  group_by(Country) %>%
  mutate(Diff_Year = Year - lag(Year),
         Diff_Size = Size - lag(Size),
         Rate = (Diff_Size/Diff_Year)/lag(Size))

growth_rateburgov1 <- growth_rateburgov %>% drop_na(Diff_Size)
mean_growth_rateburgov <- aggregate(growth_rateburgov1$Diff_Size, list(growth_rateburgov1$Country), FUN=mean)

mean_growth_rateburgov <- mean_growth_rateburgov %>%
  arrange(x) %>%
  mutate(rank = row_number())

burgov_lolli <- ggplot(mean_growth_rateburgov, aes(x = rank, y = x)) +
  geom_segment(aes(x = rank, xend = rank, y = 0, yend = x), size = 2) + geom_point(size = 3) + scale_color_grey() + coord_flip() + scale_x_continuous(breaks = mean_growth_rateburgov$rank, labels = mean_growth_rateburgov$Group.1) + labs(x = "Countries", y = "Mean Growth Rate") + theme_bw() + theme(text = element_text(size = 20))
print(burgov_lolli)

### Figure 6: Policy Ambitiousness of Carbon Taxes in Comparison
### Carbon Taxation Data is taken from Steinebach et al. (2020).

carbontax <- read.xlsx("ReplicationData.xlsx", sheet = 5) %>%
  arrange(Carbon_tax) %>%
  mutate(rank = row_number())

tax_lolli <- ggplot(carbontax, aes(x = factor(rank), y = Carbon_tax)) + 
  geom_segment(aes(x= rank, xend = rank, y = 0, yend = Carbon_tax), size = 2) + geom_point(size = 3) + scale_color_grey() + coord_flip() + scale_x_discrete(breaks = carbontax$rank, labels = carbontax$Country) + labs(x= "Countries", y = "Carbon Taxes") + theme_bw() + theme(text = element_text(size = 20))
print(tax_lolli)

### Figure 7: Policy Portfolio Development - Countries with Similar Environmental Awareness
### Data on environmental awareness is taken from the World Values Survey (Haerpfer et al. 2022)
### Countries with similar environmental awareness to Singapore: Austria, Portugal, Greece, Spain, and UK

growth_rateenv <- read.xlsx("ReplicationData.xlsx", sheet = 6) %>%
  group_by(Country) %>%
  mutate(Diff_Size = Size - lag(Size),
         Rate = (Diff_Size/lag(Size)))

envgrowth <- growth_rateenv %>% drop_na(Diff_Size)
mean_diff_size <- aggregate(envgrowth$Diff_Size, list(envgrowth$Country), FUN=mean)

mean_diff_size <- mean_diff_size %>%
  arrange(x) %>%
  mutate(rank = row_number())

envplot <- ggplot(mean_diff_size, aes(x = rank, y = x)) +
  geom_segment(aes(x = rank, xend = rank, y = 0, yend = x), size = 2) + geom_point(size = 3) + scale_color_grey() + coord_flip() + scale_x_continuous(breaks = mean_diff_size$rank, labels = mean_diff_size$Group.1) + labs(x = "Countries", y = "Mean Growth Rate") + theme_bw() + theme(text = element_text(size = 20))
print(envplot)


### Figure A1: Policy Portfolio Development of Full Country Sample - Side-by-side Plots
### full country sample is given for the appendix. We plot each individual policy portfolio development and combine them with patchwork.

library(patchwork)

#Australia

Australia <- read.xlsx("CountryGrowths.xlsx", sheet = 1)

AustraliaGrowth <- ggplot(Australia, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(AustraliaGrowth)

#Austria

Austria <- read.xlsx("CountryGrowths.xlsx", sheet = 2)

AustriaGrowth <- ggplot(Austria, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(AustriaGrowth)

#Belgium

Belgium <- read.xlsx("CountryGrowths.xlsx", sheet = 3)

BelgiumGrowth <- ggplot(Belgium, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(BelgiumGrowth)

#Canada

Canada <- read.xlsx("CountryGrowths.xlsx", sheet = 4)

CanadaGrowth <- ggplot(Canada, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(CanadaGrowth)

#Denmark

Denmark <- read.xlsx("CountryGrowths.xlsx", sheet = 5)

DenmarkGrowth <- ggplot(Denmark, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(DenmarkGrowth)

#Finland

Finland <- read.xlsx("CountryGrowths.xlsx", sheet = 6)

FinlandGrowth <- ggplot(Finland, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(FinlandGrowth)

#France

France <- read.xlsx("CountryGrowths.xlsx", sheet = 7)

FranceGrowth <- ggplot(France, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(FranceGrowth)

#Germany

Germany <- read.xlsx("CountryGrowths.xlsx", sheet = 8)

GermanyGrowth <- ggplot(Germany, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(GermanyGrowth)

#Greece

Greece <- read.xlsx("CountryGrowths.xlsx", sheet = 9)

GreeceGrowth <- ggplot(Greece, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(GreeceGrowth)

#Ireland

Ireland <- read.xlsx("CountryGrowths.xlsx", sheet = 10)

IrelandGrowth <- ggplot(Ireland, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(IrelandGrowth)

#Italy

Italy <- read.xlsx("CountryGrowths.xlsx", sheet = 11)

ItalyGrowth <- ggplot(Italy, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(ItalyGrowth)

#Netherlands

Netherlands <- read.xlsx("CountryGrowths.xlsx", sheet = 12)

NetherlandsGrowth <- ggplot(Netherlands, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(NetherlandsGrowth)

#New Zealand

NewZealand <- read.xlsx("CountryGrowths.xlsx", sheet = 13)

NewZealandGrowth <- ggplot(NewZealand, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(NewZealandGrowth)

#Norway

Norway <- read.xlsx("CountryGrowths.xlsx", sheet = 14)

NorwayGrowth <- ggplot(Norway, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(NorwayGrowth)

#Portugal

Portugal <- read.xlsx("CountryGrowths.xlsx", sheet = 15)

PortugalGrowth <- ggplot(Portugal, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(PortugalGrowth)

#Singapore

Singapore <- read.xlsx("CountryGrowths.xlsx", sheet = 16)

SingaporeGrowth <- ggplot(Singapore, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(SingaporeGrowth)

#Spain

Spain <- read.xlsx("CountryGrowths.xlsx", sheet = 17)

SpainGrowth <- ggplot(Spain, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(SpainGrowth)

#Sweden

Sweden <- read.xlsx("CountryGrowths.xlsx", sheet = 18)

SwedenGrowth <- ggplot(Sweden, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(SwedenGrowth)

#Switzerland

Switzerland <- read.xlsx("CountryGrowths.xlsx", sheet = 19)

SwitzerlandGrowth <- ggplot(Switzerland, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(SwitzerlandGrowth)

#United Kingdom

UK <- read.xlsx("CountryGrowths.xlsx", sheet = 20)

UKGrowth <- ggplot(UK, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(UKGrowth)

#United States

USA <- read.xlsx("CountryGrowths.xlsx", sheet = 21)

USAGrowth <- ggplot(USA, aes(x=Year, y=Size, color=Country)) + geom_line() + scale_color_grey() + theme_bw() + xlim(1976, 2020) + ylim(0, 0.4) + theme(text = element_text(size = 10)) + theme(legend.position = "top")

print(USAGrowth)

#Grid Arrangement All Plots

AustraliaGrowth + AustriaGrowth + BelgiumGrowth + CanadaGrowth + DenmarkGrowth + FinlandGrowth + FranceGrowth + GermanyGrowth + GreeceGrowth + IrelandGrowth + ItalyGrowth + NetherlandsGrowth + NewZealandGrowth + NorwayGrowth + PortugalGrowth + SingaporeGrowth + SpainGrowth + SwedenGrowth + SwitzerlandGrowth + UKGrowth + USAGrowth

### Figure A2: Policy Growth in Non-EU countries
### Non-EU countries compared to Singapore by Mean Growth Rate: Switzerland, USA, Australia, Canada, Norway, New Zealand

growth_ratenoneu <- read.xlsx("ReplicationData.xlsx", sheet = 7) %>%
  group_by(Country) %>%
  mutate(Diff_Year = Year - lag(Year),
         Diff_Size = Size - lag(Size),
         Rate = (Diff_Size/Diff_Year)/lag(Size))

growth_ratenoneu1 <- growth_ratenoneu %>% drop_na(Diff_Size)
mean_growth_ratenoneu <- aggregate(growth_ratenoneu1$Diff_Size, list(growth_ratenoneu1$Country), FUN=mean)

mean_growth_ratenoneu <- mean_growth_ratenoneu %>%
  arrange(x) %>%
  mutate(rank = row_number())

noneu_lolli <- ggplot(mean_growth_ratenoneu, aes(x = rank, y = x)) +
  geom_segment(aes(x = rank, xend = rank, y = 0, yend = x), size = 2) + geom_point(size =3) + scale_color_grey() + coord_flip() + scale_x_continuous(breaks = mean_growth_ratenoneu$rank, labels = mean_growth_ratenoneu$Group.1) + labs(x = "Countries", y = "Mean Growth Rate") + theme_bw() + theme(text = element_text(size = 20))
print(noneu_lolli)

### Figure A3: Policy Growth in countries with high population density
### sample of High Population Density countries: Netherlands, Belgium, UK
### Data on population density stems from the United Nations (2022)

growth_ratesize <- read.xlsx("ReplicationData.xlsx", sheet = 8) %>%
  group_by(Country) %>%
  mutate(Diff_Year = Year - lag(Year),
         Diff_Size = Size - lag(Size),
         Rate = (Diff_Size/Diff_Year)/lag(Size))

growth_ratesize1 <- growth_ratesize %>% drop_na(Diff_Size)
mean_growth_ratesize <- aggregate(growth_ratesize1$Diff_Size, list(growth_ratesize1$Country), FUN=mean)

mean_growth_ratesize <- mean_growth_ratesize %>%
  arrange(x) %>%
  mutate(rank = row_number())

size_lolli <- ggplot(mean_growth_ratesize, aes(x = rank, y = x)) +
  geom_segment(aes(x = rank, xend = rank, y = 0, yend = x), size = 2) + geom_point(size =3) + scale_color_grey() + coord_flip() + scale_x_continuous(breaks = mean_growth_ratesize$rank, labels = mean_growth_ratesize$Group.1) + labs(x = "Countries", y = "Mean Growth Rate") + theme_bw() + theme(text = element_text(size = 20))
print(size_lolli)


### Figure A4: Carbon footprint per capita(t), year 2020
### Data on carbon footprint per capita(t) comes from the 2022 World Population Review

carbonfootprint <- read.xlsx("ReplicationData.xlsx", sheet = 9) %>%
  arrange(Carbon_footprint_pct_2020) %>%
  mutate(rank = row_number())

footprint_lolli <- ggplot(carbonfootprint, aes(x = factor(rank), y = Carbon_footprint_pct_2020)) +
  geom_segment(aes(x = rank, xend = rank, y = 0, yend = Carbon_footprint_pct_2020), size = 2) + geom_point(size=3) + scale_color_grey() + coord_flip() + scale_x_discrete(breaks = carbonfootprint$rank, labels = carbonfootprint$Country) + labs(x= "Countries", y = "Carbon Footprint per capita (t)") + theme_bw() + theme(text = element_text(size = 20))
print(footprint_lolli)


### Figure A5: Regional policy growth (Asia and Oceania), for time period of 1976 to 2005
### Compared to Singapore in Mean Growth Rate, South Korea, Australia, and New Zealand

growth_ratesk <- read.xlsx("ReplicationData.xlsx", sheet = 10) %>%
  group_by(Country) %>%
  mutate(Diff_Size = Size - lag(Size),
         Rate = (Diff_Size/lag(Size)))

skgrowth <- growth_ratesk %>% drop_na(Diff_Size)
mean_diff_size <- aggregate(skgrowth$Diff_Size, list(skgrowth$Country), FUN=mean)

mean_diff_size <- mean_diff_size %>%
  arrange(x) %>%
  mutate(rank = row_number())

skplot <- ggplot(mean_diff_size, aes(x = rank, y = x)) +
  geom_segment(aes(x = rank, xend = rank, y = 0, yend = x), size = 2) + geom_point(size = 3) + scale_color_grey() + coord_flip() + scale_x_continuous(breaks = mean_diff_size$rank, labels = mean_diff_size$Group.1) + labs(x = "Countries", y = "Mean Growth Rate") + theme_bw() + theme(text = element_text(size = 20))
print(skplot)

### Figure A6: Policy Growth in South Korea and Singapore (1976 to 2005)
### Policy portfolio development of Singapore and South Korea in comparison, sample data is taken from the CONSENSUS project

dem <- read.xlsx("CountryGrowths.xlsx", sheet = 22)

demdata <- ggplot(dem, aes(x=Year, y=Size, color=Country)) + geom_line(aes(linetype = Country), size = 2) + scale_linetype_manual(values = c("solid", "dashed")) + scale_color_grey() + theme_bw() + xlim(1976, 2005) + ylim(0, 0.4) + theme(text = element_text(size = 20))

print(demdata)
